package com.excel.excelUtil;

import com.excel.excelUtil.dto.LawFirmInfo;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author zhuangqi
 * @@date 2017/3/22.
 */
public class TestMain {
    public static void main(String[] args) {
//        Field[] fields  = LawFirmInfo.class.getDeclaredFields();
//        for (int i = 0; i < fields.length; i++) {
//            Field field = fields[i];
//            Annotation annotation = field.getAnnotation(ExcelColumn.class);
//            if (annotation instanceof ExcelColumn){
//                ExcelColumn excelColumn = (ExcelColumn) annotation;
//                System.out.println(field.getName());
//                System.out.println(excelColumn.cellName());
//            }
//        }

        printGettersSetters(LawFirmInfo.class);
    }

    public static void printGettersSetters(Class aClass){
        Method[] methods = aClass.getMethods();

        for(Method method : methods){
            if(isGetter(method));
//            if(isSetter(method)) System.out.println("setter: " + method);
        }
    }

    public static boolean isGetter(Method method){
        if(!method.getName().startsWith("get"))      return false;
        if(method.getParameterTypes().length != 0)   return false;
        if(void.class.equals(method.getReturnType())) return false;
        System.out.println(method.getName().substring(3));
        return true;
    }

    public static boolean isSetter(Method method){
        if(!method.getName().startsWith("set")) return false;
        if(method.getParameterTypes().length != 1) return false;
        return true;
    }
}
